/*
 * Copyright (C) 2025 Tsingteng MicroSystem
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * @file routing_manager.c
 * @brief 路由管理模块实现
 */
#include "nfa_routing.h"
#include "nci_rf.h"
#include <string.h>
#include "nfc_log_api.h"
#include "priority_queue.h"
#include "nci_module.h"
#include "nfa_discover.h"
#include "nfc_config_api.h"
#include "ee_int.h"
#include "discover_int.h"

#if IS_FEATURE_ON(NCI_FEATURE_ROUTING)

#define GET_RT_LOCK_OR_RETURN(ret) \
    if (osi_mutex_lock(&s_routing_table_lock) != NFC_STATUS_OK) { \
        return ret; \
    } \

#define GET_RT_LOCK() GET_RT_LOCK_OR_RETURN(NCI_STATUS_EXT_GET_LOCK_FAILED)

#define RELEASE_RT_LOCK() \
    if (osi_mutex_unlock(&s_routing_table_lock) != NFC_STATUS_OK) { \
        NFCLOG_E("RELEASE_RT_LOCK failed"); \
    }

#define HCE_MASK_TECH_A 0x01
#define HCE_MASK_TECH_B 0x02

static tMUTEX s_routing_table_lock = MUTEX_INIT_VAL("routing_table");
/* 由上层设置的默认空AID路由 */
static tNCI_NFCEE_ID s_usr_aid_route = NCI_INVALID_ROUTE;
/* 由上层设置的默认空AID路由的power status */
static tNCI_EE_PWR_STATE s_usr_aid_pwr = NCI_INVALID_POWER_STATE;
/* 由上层设置的默认System Code路由 */
static tNCI_NFCEE_ID s_usr_sc_route = NCI_INVALID_ROUTE;
/* 由上层设置的默认ISO Dep路由 */
static tNCI_NFCEE_ID s_usr_isodep_route = NCI_INVALID_ROUTE;
/* 由上层设置的默认Tech A、B路由 */
static tNCI_NFCEE_ID s_usr_offhost_route = NCI_INVALID_ROUTE;
/* 由上层设置的默认Tech F路由 */
static tNCI_NFCEE_ID s_usr_nfcf_route = NCI_INVALID_ROUTE;
/* 记录EE的Discover Req状态 */
static tNCI_EE_DISCOVER_REQ s_ee_infos = {0};
/* 记录根据路由最终结果设置的RF listen参数 */
static uint8_t s_listen_param = 0;

/**
 * @brief 检查传入id的ee是否存在信息，若存在，说明ee是enable状态
 */
static bool check_ee_info_unlock(uint8_t ee_id) {
    for (int i = 0; i < s_ee_infos.ee_num; i++) {
        if (s_ee_infos.infos[i].ee_id == ee_id) {
            return true;
        }
    }
    return false;
}

/**
 * @brief 更新默认的路由表
 */
static tNCI_STATUS update_full_route() {
    const tNFC_CF *default_rt = nfc_config_get();
    const tNFC_VENDOR_CONFIG *vnd_rt = &default_rt->vendor_cf;
    // 日志格式为 route: (USER ROUTE) - (DEFAULT ROUTE)
    NFCLOG_I("aid route:0x%X-0x%X, sc route:0x%X-0x%X, iso route:0x%X-0x%X, offhost route:0x%X-0x%X, nfcf route:0x%X-0x%X",
              s_usr_aid_route, vnd_rt->aid_route, s_usr_sc_route, vnd_rt->system_code_route, s_usr_isodep_route,
              vnd_rt->iso_dep_route, s_usr_offhost_route, vnd_rt->offhost_route, s_usr_nfcf_route, vnd_rt->offhost_route_felica);
    // 1. 如果上层修改了默认路由，以上层修改的为准
    // 2. 如果上层修改了AID的power state，以上层修改的为准
    // 3. AID以外路由的power state，如果是路由到DH，默认为0x11，如果路由到Offhost，默认为0x3B
    GET_RT_LOCK();
    tNCI_NFCEE_ID aid_route = (s_usr_aid_route != NCI_INVALID_ROUTE)? s_usr_aid_route: vnd_rt->aid_route;
    tNCI_EE_PWR_STATE aid_pwr = (s_usr_aid_pwr != NCI_INVALID_POWER_STATE)? s_usr_aid_pwr: default_rt->aid_pwr;
    tNCI_NFCEE_ID sc_route = (s_usr_sc_route != NCI_INVALID_ROUTE)? s_usr_sc_route: vnd_rt->system_code_route;
    tNCI_EE_PWR_STATE sc_pwr = (sc_route == NCI_DH_NFCEE_ID)? NCI_HOST_PWR_STATE: vnd_rt->system_code_power_state;
    if (sc_route != NCI_DH_NFCEE_ID && !check_ee_info_unlock(sc_route) && EE_IS_SUPPORT_DH) {
        sc_route = NCI_DH_NFCEE_ID;
        sc_pwr = NCI_HOST_PWR_STATE;
    }
    tNCI_NFCEE_ID iso_route = (s_usr_isodep_route != NCI_INVALID_ROUTE)? s_usr_isodep_route: vnd_rt->iso_dep_route;
    tNCI_EE_PWR_STATE iso_pwr = (iso_route == NCI_DH_NFCEE_ID)? NCI_HOST_PWR_STATE: NCI_OFFHOST_PWR_STATE;
    if (iso_route != NCI_DH_NFCEE_ID && !check_ee_info_unlock(iso_route) && EE_IS_SUPPORT_DH) {
        iso_route = NCI_DH_NFCEE_ID;
        iso_pwr = NCI_HOST_PWR_STATE;
    }
    tNCI_NFCEE_ID offhost_route = (s_usr_offhost_route != NCI_INVALID_ROUTE)? s_usr_offhost_route: vnd_rt->offhost_route;
    tNCI_EE_PWR_STATE offhost_pwr = (offhost_route == NCI_DH_NFCEE_ID)? NCI_HOST_PWR_STATE: NCI_OFFHOST_PWR_STATE;
    tNCI_NFCEE_ID nfcf_route = (s_usr_nfcf_route != NCI_INVALID_ROUTE)? s_usr_nfcf_route: vnd_rt->offhost_route_felica;
    tNCI_EE_PWR_STATE nfcf_pwr = (nfcf_route == NCI_DH_NFCEE_ID)? NCI_HOST_PWR_STATE: NCI_OFFHOST_PWR_STATE;
    RELEASE_RT_LOCK();

    ee_route_remove_aid(NULL, 0);
    ee_route_add_aid(aid_route, aid_pwr, NULL, 0, NCI_ROUTING_QUALIFIER_AID_PREFIX);

    ee_route_remove_sys_code(default_rt->sys_code);
    ee_route_add_sys_code(sc_route, sc_pwr, default_rt->sys_code);

    ee_route_remove_protocol(NCI_RF_PROTOCOL_ISO_DEP);
    ee_route_add_protocol(iso_route, iso_pwr, NCI_RF_PROTOCOL_ISO_DEP);

    // 如果config中配置支持HCE A/B, 则当SE无效时，默认路由到00，否则不添加到路由表
    NFCLOG_D("default_hce_tech: 0x%02X", default_rt->vendor_cf.default_hce_tech);
    tNCI_NFCEE_ID tech_a_route = default_rt->vendor_cf.default_hce_tech & HCE_MASK_TECH_A? NCI_DH_NFCEE_ID: NCI_INVALID_ROUTE;
    tNCI_NFCEE_ID tech_a_pwr = NCI_HOST_PWR_STATE;
    tNCI_NFCEE_ID tech_b_route = default_rt->vendor_cf.default_hce_tech & HCE_MASK_TECH_B? NCI_DH_NFCEE_ID: NCI_INVALID_ROUTE;
    tNCI_NFCEE_ID tech_b_pwr = NCI_HOST_PWR_STATE;
    tNCI_NFCEE_ID tech_f_route = NCI_DH_NFCEE_ID;
    tNCI_NFCEE_ID tech_f_pwr = NCI_HOST_PWR_STATE;
    GET_RT_LOCK();
    // 如果默认Tech路由的EE支持该Tech，才会最终把路由设置下去，否则路由会设置到00
    for (int i = 0; i < s_ee_infos.ee_num; i++) {
        NFCLOG_D("EE: 0x%X la_protocol = 0x%x, lb_protocol = 0x%x, lf_protocol = 0x%x",
                  s_ee_infos.infos[i].ee_id, s_ee_infos.infos[i].la_protocol,
                  s_ee_infos.infos[i].lb_protocol, s_ee_infos.infos[i].lf_protocol);
        if (s_ee_infos.infos[i].ee_id == offhost_route) {
            if (s_ee_infos.infos[i].la_protocol) {
                tech_a_route = offhost_route;
                tech_a_pwr = offhost_pwr;
                s_listen_param |= NCI_RF_DISCOVER_LISTEN_A;
            }
            if (s_ee_infos.infos[i].lb_protocol) {
                tech_b_route = offhost_route;
                tech_b_pwr = offhost_pwr;
                s_listen_param |= NCI_RF_DISCOVER_LISTEN_B;
            }
        }
        if (s_ee_infos.infos[i].ee_id == nfcf_route && s_ee_infos.infos[i].lf_protocol) {
            tech_f_route = nfcf_route;
            tech_f_pwr = nfcf_pwr;
            s_listen_param |= NCI_RF_DISCOVER_LISTEN_F;
        }
    }
    RELEASE_RT_LOCK();
    rf_set_discover_param(-1, s_listen_param);
    ee_route_remove_tech(NCI_RF_TECH_A);
    ee_route_add_tech(tech_a_route, tech_a_pwr, NCI_RF_TECH_A);
    ee_route_remove_tech(NCI_RF_TECH_B);
    ee_route_add_tech(tech_b_route, tech_b_pwr, NCI_RF_TECH_B);
    ee_route_remove_tech(NCI_RF_TECH_F);
    ee_route_add_tech(tech_f_route, tech_f_pwr, NCI_RF_TECH_F);
    return NCI_STATUS_OK;
}

/**
 * @brief 向路由表中添加AID路由
 *
 * @note 如果同一个AID已经存在，则更新路由表中的AID路由
 *
 * @param ee_id 路由项所属的NFCEE ID
 * @param power_state 路由项的电源状态
 * @param aid AID，NULL表示AID*
 * @param aid_len AID长度
 * @param aid_info AID信息，是否为精确AID
 *
 * @return 添加成功返回NCI_STATUS_OK，否则返回对应错误码
 */
tNCI_STATUS nfa_routing_add_aid(tNCI_NFCEE_ID ee_id, tNCI_EE_PWR_STATE power_state, uint8_t *aid, uint8_t aid_len, tNCI_AID_INFO aid_info) {
    tNCI_EE_PWR_STATE pwr = power_state & NCI_POWER_STATE_MASK;
    return ee_route_add_aid(ee_id, pwr, aid, aid_len, aid_info);
}

/**
 * @brief 删除路由表中的AID路由
 *
 * @param aid AID，NULL表示AID*
 * @param aid_len AID长度
 *
 * @return 删除成功返回NCI_STATUS_OK，否则返回对应错误码
 */
tNCI_STATUS nfa_routing_remove_aid(uint8_t *aid, uint8_t aid_len) {
    return ee_route_remove_aid(aid, aid_len);
}

/**
 * @brief 添加SystemCode类型路由
 *
 * @param ee_id 路由项所属的NFCEE ID
 * @param power_state 路由项的电源状态
 * @param system_code SystemCode编码，高字节在前
 *
 * @return 添加成功返回NCI_STATUS_OK，否则返回对应错误码
 */
tNCI_STATUS nfa_routing_add_sys_code(tNCI_NFCEE_ID ee_id, tNCI_EE_PWR_STATE power_state, uint16_t system_code) {
    tNCI_STATUS ret = NCI_STATUS_OK;
    tNCI_EE_PWR_STATE pwr = power_state & NCI_POWER_STATE_MASK;
    if (system_code == 0xFFFF) {
        NFCLOG_W("should not add system code 0xFFFF");
        return NCI_STATUS_EXT_INVALID_PARAM;
    }
    GET_RT_LOCK();
    ret = ee_route_add_sys_code(ee_id, pwr, system_code);
    if (ret == NCI_STATUS_OK) {
        // 添加system code路由成功后，打开type F listen
        s_listen_param |= NCI_RF_DISCOVER_LISTEN_F;
    }
    RELEASE_RT_LOCK();
    return ret;
}

/**
 * @brief 移除SystemCode类型路由
 *
 * @param system_code 需要移除的SystemCode编码，高字节在前
 *
 * @return 删除成功返回NCI_STATUS_OK，否则返回对应错误码
 */
tNCI_STATUS nfa_routing_remove_sys_code(uint16_t system_code) {
    tNCI_STATUS ret = NCI_STATUS_OK;
    GET_RT_LOCK();
    ret = ee_route_remove_sys_code(system_code);
    if (ret == NCI_STATUS_OK) {
        // 删除system code路由成功后，移除type F listen
        // 目前Android应用场景为顶层应用才能动态注册system code，所以默认只有一个应用system code即可
        s_listen_param &= ~NCI_RF_DISCOVER_LISTEN_F;
    }
    RELEASE_RT_LOCK();
    return ret;
}

/**
 * @brief 清除指定类型的所有路由
 *
 * @param type 路由类型
 *
 * @return 清除成功返回NCI_STATUS_OK，否则返回对应错误码
 */
tNCI_STATUS nfa_routing_clear(tNCI_ROUTING_ENTRY_TYPE type) {
    return ee_route_clear(type);
}

/**
 * @brief 清除所有路由
 *
 * @return 清除成功返回NCI_STATUS_OK，否则返回对应错误码
 */
tNCI_STATUS nfa_routing_clear_all() {
    return ee_route_clear_all();
}

/**
 * @brief 修改默认路由设置
 *
 * @param type 需要修改的默认路由类型
 * @param route 指定的路由EE
 * @param pwr 指定路由的power status, 只对aid路由生效
 *
 * @return 清除成功返回NCI_STATUS_OK，否则返回对应错误码
 */
tNCI_STATUS nfa_routing_set_user_route(tNCI_USER_ROUTE_TYPE type, tNCI_NFCEE_ID route, tNCI_EE_PWR_STATE power_state) {
    GET_RT_LOCK();
    bool set = true;
    tNCI_EE_PWR_STATE pwr = power_state & NCI_POWER_STATE_MASK;
    uint8_t pre_route = NCI_INVALID_ROUTE;
    uint8_t pre_pwr = NCI_INVALID_POWER_STATE;
    switch (type) {
        case USR_ROUTE_TYPE_AID:
            pre_route = s_usr_aid_route;
            pre_pwr = s_usr_aid_pwr;
            s_usr_aid_route = route;
            s_usr_aid_pwr = pwr;
            NFCLOG_I("empty aid route change: 0x%X -> 0x%X, pwr: 0x%X -> 0x%X", pre_route, route, pre_pwr, pwr);
            break;
        case USR_ROUTE_TYPE_SYS_CODE:
            pre_route = s_usr_sc_route;
            s_usr_sc_route = route;
            break;
        case USR_ROUTE_TYPE_ISODEP:
            pre_route = s_usr_isodep_route;
            s_usr_isodep_route = route;
            break;
        case USR_ROUTE_TYPE_OFFHOST:
            pre_route = s_usr_offhost_route;
            s_usr_offhost_route = route;
            break;
        case USR_ROUTE_TYPE_NFCF:
            pre_route = s_usr_nfcf_route;
            s_usr_nfcf_route = route;
            break;
        default:
            set = false;
            NFCLOG_W("not support type: %d", type);
            break;
    }
    if (set) {
        NFCLOG_I("user route(%d) change: 0x%X -> 0x%X", type, pre_route, route);
    }
    RELEASE_RT_LOCK();
    return set? NCI_STATUS_OK: NCI_STATUS_EXT_FAILED;
}

/**
 * @brief 清除路由设置，恢复为config中配置的默认值
 *
 */
tNCI_STATUS nfa_routing_clear_all_user_route() {
    GET_RT_LOCK();
    NFCLOG_I("recovery all route to default");
    s_usr_aid_route = NCI_INVALID_ROUTE;
    s_usr_aid_pwr = NCI_INVALID_POWER_STATE;
    s_usr_sc_route = NCI_INVALID_ROUTE;
    s_usr_isodep_route = NCI_INVALID_ROUTE;
    s_usr_offhost_route = NCI_INVALID_ROUTE;
    s_usr_nfcf_route = NCI_INVALID_ROUTE;
    RELEASE_RT_LOCK();
    return NCI_STATUS_OK;
}

/**
 * @brief 更新路由表，将路由表中的路由项发送给NFCC
 *
 * @return 更新成功返回NCI_STATUS_OK，否则返回对应错误码
 */
tNCI_STATUS nfa_routing_commit() {
    tNCI_STATUS ret = NCI_STATUS_OK;
    update_full_route();
    rf_lock();
    tNCI_RFST rfst = nfa_rf_get_state();
    if (rfst != NCI_RFST_IDLE) {
        ret = nfa_rf_stop_discovery();
    }
    if (ret == NCI_STATUS_OK) {
        ret = ee_route_commit();
    } else {
        NFCLOG_E("stop rf discovery failed!");
    }
    if (rfst != NCI_RFST_IDLE) {
        nfa_rf_start_discovery();
    }
    rf_unlock();
    return ret;
}

/**
 * @brief 获取config中配置的默认路由
 *
 * @param type 传入获取的默认路由类型
 *
 * @return 返回传入类型的默认路由
 */
uint8_t nfa_routing_get_default_route(tNCI_USER_ROUTE_TYPE type) {
    uint8_t route = 0x00;
    const tNFC_CF *default_rt = nfc_config_get();
    const tNFC_VENDOR_CONFIG *vnd_rt = &default_rt->vendor_cf;
    switch (type) {
        case USR_ROUTE_TYPE_AID:
            route = vnd_rt->aid_route;
            break;
        case USR_ROUTE_TYPE_SYS_CODE:
            route = vnd_rt->system_code_route;
            break;
        case USR_ROUTE_TYPE_ISODEP:
            route = vnd_rt->iso_dep_route;
            break;
        case USR_ROUTE_TYPE_OFFHOST:
            route = vnd_rt->offhost_route;
            break;
        case USR_ROUTE_TYPE_NFCF:
            route = vnd_rt->offhost_route_felica;
            break;
        default:
            NFCLOG_E("Not support type: %d", type);
            break;
    }
    return route;
}

/**
 * @brief 获取config中配置的offhost的路由的对应EE的id
 *
 * @note 其中，一种类型的offhost对应的EE id可能存在多个
 *
 * @param ee_id 用于存放传入类型offhost对应ee id的指针结构体
 *
 * @return 返回传入类型的默认路由
 */
tNCI_STATUS nfa_routing_get_offhost_route_id(tNCI_OFFHOST_ROUTE_TYPE type, tNCI_OFFHOST_EE_ID* ee_id) {
    if (!ee_id) {
        NFCLOG_E("invalid param!");
        return NCI_STATUS_INVALID_PARAM;
    }
    tNCI_STATUS ret = NCI_STATUS_OK;
    const tNFC_CF_ARRAY def_uicc_rt = nfc_config_get()->vendor_cf.offhost_route_uicc;
    const tNFC_CF_ARRAY def_ese_rt = nfc_config_get()->vendor_cf.offhost_route_ese;
    switch (type) {
        case OFFHOST_UICC:
            ee_id->num = def_uicc_rt.len;
            for (int i = 0; i < ee_id->num && i < MAX_EE_NUM_OF_OFFHOST; i++) {
                ee_id->id[i] = def_uicc_rt.data[i];
            }
            break;
        case OFFHOST_ESE:
            ee_id->num = def_ese_rt.len;
            for (int i = 0; i < ee_id->num && i < MAX_EE_NUM_OF_OFFHOST; i++) {
                ee_id->id[i] = def_ese_rt.data[i];
            }
            break;
        default:
            NFCLOG_E("Not support type: %d", type);
            ret = NCI_STATUS_INVALID_PARAM;
            break;
    }
    return ret;
}
/**
 * @brief 获取支持的AID匹配模式

 * @return 返回AID匹配模式
 */
uint8_t nfa_routing_get_aid_match_mode() {
    return nfc_config_get()->aid_match_mode;
}
#if IS_FEATURE_ON(NCI_FEATURE_EE_DH)
/**
 * @brief 设置secure NFC状态
 *
 * @note secure NFC状态下，只有screen on unlocked状态下的DH才能被路由到
 * @note 不影响Offhost的路由
 * @note 需要commit routing后生效
 * @param enable 是否开启secure NFC
 *
 * @return 设置成功返回NCI_STATUS_OK，否则返回对应错误码
 */
tNCI_STATUS nfa_routing_set_secure_nfc(bool enable) {
    return ee_route_set_secure_nfc(enable);
}
#endif // IS_FEATURE_ON(NCI_FEATURE_EE_DH)

/**
 * @brief 注册回调函数，监听EE的事件
 */
static void nfcee_callback(tNCI_EE_EVT event, tNCI_EE_EVT_DATA* p_data) {
    NFCLOG_D("get event: %d", event);
    switch (event) {
        case NCI_EE_DISCOVER_REQ_EVT:
            GET_RT_LOCK_OR_RETURN();
            osi_memcpy_s(&s_ee_infos, sizeof(tNCI_EE_DISCOVER_REQ), &p_data->discover_req, sizeof(tNCI_EE_DISCOVER_REQ));
            // 不通知上层，直接更新路由表
            nfa_routing_commit();
            RELEASE_RT_LOCK();
            break;
        default:
            break;
    }
}

/**
 * @brief 初始化路由管理器
 */
static tNCI_STATUS init(const tNCI_MODULE_INIT_CFG *p_cfg) {
    (void) p_cfg;
    tNCI_STATUS ret = NCI_STATUS_OK;
    if (osi_mutex_init_with_attr(&s_routing_table_lock, true) != NFC_STATUS_OK) {
        NFCLOG_E("Failed to init routing table lock");
        return NCI_STATUS_EXT_FAILED;
    }

    GET_RT_LOCK();
    if (EE_IS_SUPPORT_DH) {
        // 默认AB打开，用于支持HCE。如果不支持DH时，完全由Offhost控制
        s_listen_param = NCI_RF_DISCOVER_LISTEN_A|NCI_RF_DISCOVER_LISTEN_B;
    }
    ee_register_cback(nfcee_callback);
    // 注册EE监听前，EE的Discover Req参数就可能已经确定，因此需要有一个初始化参数
    ee_get_discovery_req(&s_ee_infos);
    RELEASE_RT_LOCK();

    return ret;
}

/**
 * @brief 销毁路由管理器
 */
static tNCI_STATUS deinit(bool is_shutdown) {
    (void) is_shutdown;
    GET_RT_LOCK();
    ee_deregister_cback(nfcee_callback);
    s_listen_param = 0;
    RELEASE_RT_LOCK();
    osi_mutex_deinit(&s_routing_table_lock);
    return NCI_STATUS_OK;
}

/**
 * @brief Routing管理模块dump函数
 */
static void dump(int fd) {
    const tNFC_CF *default_rt = nfc_config_get();
    const tNFC_VENDOR_CONFIG *vnd_rt = &default_rt->vendor_cf;
    osi_dump(fd, "CONFIG Default Route:");
    osi_dump(fd, "- empty AID: 0x%02X, Power State: 0x%02X", vnd_rt->aid_route, default_rt->aid_pwr);
    osi_dump(fd, "- System Code: 0x%02X, Route: 0x%02X, Power State: 0x%02X", default_rt->sys_code, vnd_rt->system_code_route, vnd_rt->system_code_power_state);
    osi_dump(fd, "- ISO Dep: 0x%02X", vnd_rt->iso_dep_route);
    osi_dump(fd, "- TYPE A: 0x%02X", vnd_rt->offhost_route);
    osi_dump(fd, "- TYPE B: 0x%02X", vnd_rt->offhost_route);
    osi_dump(fd, "- TYPE F: 0x%02X", vnd_rt->offhost_route_felica);
    osi_dump(fd, "USER Default Route:");
    osi_dump(fd, "- empty AID: 0x%02X, Power State: 0x%02X", s_usr_aid_route, s_usr_aid_pwr);
    osi_dump(fd, "- System Code: 0x%02X, Route: 0x%02X, Power State: 0x%02X", default_rt->sys_code, s_usr_sc_route, vnd_rt->system_code_power_state);
    osi_dump(fd, "- ISO Dep: 0x%02X", s_usr_isodep_route);
    osi_dump(fd, "- TYPE A: 0x%02X", s_usr_offhost_route);
    osi_dump(fd, "- TYPE B: 0x%02X", s_usr_offhost_route);
    osi_dump(fd, "- TYPE F: 0x%02X", s_usr_nfcf_route);
    osi_dump(fd, "Route Listen Param: 0x%X", s_listen_param);
}

/**
 * @brief 路由管理器模块
 */
tNCI_MODULE g_routing_manager = {
    .name = "ROUTING_MANAGER",
    .state = NCI_MODULE_STATE_DISABLED,
    .init = init,
    .deinit = deinit,
    .dump = dump,
};

#endif // IS_FEATURE_ON(NCI_FEATURE_ROUTING)
